package com.jingsheng.jingshengcity.mvp.ui.activity.wallet;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.UiUtils;
import com.jingsheng.jingshengcity.R;
import com.jingsheng.jingshengcity.di.component.DaggerBankCardComponent;
import com.jingsheng.jingshengcity.di.module.BankCardModule;
import com.jingsheng.jingshengcity.mvp.contract.BankCardContract;
import com.jingsheng.jingshengcity.mvp.model.entity.BankCardEntity;
import com.jingsheng.jingshengcity.mvp.presenter.BankCardPresenter;
import com.jingsheng.jingshengcity.mvp.ui.adapter.BankCardActivityAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * Created by Administrator on 2017/5/13.
 */

public class BankCardActivity extends BaseActivity<BankCardPresenter> implements BankCardContract.View {

    @NonNull
    @BindView(R.id.rv_list)
    RecyclerView mRecyclerView;

    private List<BankCardEntity> mList = new ArrayList<>();

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerBankCardComponent
                .builder()
                .appComponent(appComponent)
                .bankCardModule(new BankCardModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView() {
        setTitle("银行卡管理");
        return R.layout.activity_bank_card;
    }

    @Override
    public void initData() {

        mList.add(new BankCardEntity(BankCardEntity.ITEM));
        mList.add(new BankCardEntity(BankCardEntity.ITEM));
        mList.add(new BankCardEntity(BankCardEntity.ADD));

        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        BankCardActivityAdapter mBankCardActivityAdapter = new BankCardActivityAdapter(mList);
        mBankCardActivityAdapter.openLoadAnimation();
        mRecyclerView.setAdapter(mBankCardActivityAdapter);

        mBankCardActivityAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()){
                    case R.id.ll_add_item:
                        toAdd();
                        break;
                }
            }
        });
    }

    private void toAdd() {
        Intent intent = new Intent(this, BindBankCardActivity.class);
        startActivity(intent);
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        UiUtils.SnackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        UiUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public boolean useFragment() {
        return false;
    }


}